package com.asktgapp.utils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.asktgapp.R;


/**
 * time:2017/11/6
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */
@SuppressLint("ValidFragment")
public class SelectDialogFragment extends DialogFragment implements View.OnClickListener {

    private setResult result;

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.take_photo) {
            result.onTake();
            dismiss();
        } else if (i == R.id.select_photo) {
            result.onSelect();
            dismiss();
        }
    }


    public interface setResult {
        void onTake();

        void onSelect();
    }

    @SuppressLint("ValidFragment")
    public SelectDialogFragment(setResult result) {
        this.result = result;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialogfragment_select_img);
        dialog.findViewById(R.id.take_photo).setOnClickListener(this);
        dialog.findViewById(R.id.select_photo).setOnClickListener(this);
        dialog.findViewById(R.id.cancle).setOnClickListener(this);
//        takePhoto.onPickFromCapture(imageUri);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams p = window.getAttributes();
        WindowManager m = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        window.setBackgroundDrawableResource(R.drawable.dialog_bg);
        Display d = m.getDefaultDisplay();
        p.width = (int) (d.getWidth() * 0.9);
        p.gravity = Gravity.BOTTOM;
        p.windowAnimations = R.style.popwin_anim_style;
        window.setAttributes(p);
        return dialog;
    }
}
